/**
* Created by wangshuyi on 2017-9-8 13:40:51.
*/

'use strict';

const extend = require('extend');
const logger = require('log4js').getLogger("sys");

const CommonService = require("../../service/util/dbService");
const Model = require("../../module/prize/EventModel");
const tool = require("../../module/util/tool");

const defaultParams = {
    model : Model
};

class ModuleService extends CommonService{
    constructor(param){
        super(param);
        this.opts = extend(true, {}, this.opts, defaultParams, param);
        this._name = "PrizeEventService";
    }
    save(curUser, data){
        if(data.eventDateStart){
            data.eventDateStart = tool.string2date(data.eventDateStart+' 00:00:00', 'yyyy-MM-dd hh:mm:ss')
        }
        if(data.eventDateEnd){
            console.log(data.eventDateEnd + ' 23:59:59');
            data.eventDateEnd = tool.string2date(data.eventDateEnd+' 23:59:59', 'yyyy-MM-dd hh:mm:ss')
        }
            if(data.receiveDate){
            data.receiveDate = tool.string2date(data.receiveDate+' 23:59:59', 'yyyy-MM-dd hh:mm:ss')
        }
        return super.save(curUser, data);
    }
    updateById(curUser, id, data){
        if(data.eventDateStart){
            data.eventDateStart = tool.string2date(data.eventDateStart+' 00:00:00', 'yyyy-MM-dd hh:mm:ss')
        }
        if(data.eventDateEnd){
            data.eventDateEnd = tool.string2date(data.eventDateEnd+' 23:59:59', 'yyyy-MM-dd hh:mm:ss')
        }
        if(data.receiveDate){
            data.receiveDate = tool.string2date(data.receiveDate+' 23:59:59', 'yyyy-MM-dd hh:mm:ss')
        }
        return super.updateById(curUser, id, data);
    }
}

module.exports = new ModuleService();


